package com.gin.no_gay_alliance.utils;

import android.content.Context;
import android.os.Build;
import android.view.View;
import android.widget.PopupMenu;

import androidx.annotation.MenuRes;

/**
 * 弹出菜单工具类
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/6 20:00
 **/
public class PopupMenuUtils {
    /**
     * 创建一个弹出菜单
     *
     * @param context  上下文
     * @param anchor   触发位置的view
     * @param id       彩蛋id
     * @param listener 菜单项点击监听
     * @return 菜单
     */
    public static PopupMenu create(Context context, View anchor, @MenuRes int id, PopupMenu.OnMenuItemClickListener listener) {
        PopupMenu popupMenu = new PopupMenu(context, anchor);
        popupMenu.inflate(id);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            popupMenu.setForceShowIcon(true);
        }
        popupMenu.setOnMenuItemClickListener(listener);
        return popupMenu;
    }
}
